#!/bin/bash
## 不是自动安装，需要复制以下内容手动复制
## 需要添加各个运维主机组或主机名
## 后面还有一些操作示例
## centos 7

step=1

#安装Ansible，安装配置yum源(使用aliyun)
#
echo "\n******** step $step 添加配置yum源:/etc/yum.repos.d/aliBase.repo ********"

sudo tee /etc/yum.repos.d/aliBase.repo <<-'EOF'
[Base]
name=aliBase
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever
 
# cat aliEpel.repo
[aliEpel]
name=aliEpel
baseurl=https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/
enabled=1
gpgcheck=0
EOF



let step=step+1
echo "\n******** step $step 开始安装 ansible ********"
yum install -y ansible


## 以下均需要手工操作：


##添加环境变量以便vi能正常显示中文注释.
vim /etc/profile
##添加:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
source /etc/profile

##修改主机及组配置
cd /etc/ansible
cp hosts hosts.bak
cat /dev/null > hosts
vim /etc/ansible/hosts
##添加:
[develop]
172.30.1.36
172.30.1.45

#ssh无密码认证 DSA和RSA选择任一种即可
#ssh无密码认证 DSA
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

##yum -y install openssh-clients
ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.30.1.36
ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.30.1.45

# #ssh无密码认证 RSA
# ssh-keygen -t rsa
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 600 ~/.ssh/authorized_keys

# #注意文件是id_dsa.pub还是id_rsa.pub，否则会出现ssh-copy-id: ERROR: No identities found
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.30.1.36
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.30.1.45


